package muilt;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.luculent.base.section.FPBSend;

public class RunHttp3 {
	@Test
	public void test() throws Exception{
		List<CompletableFuture> a = Lists.newArrayList(); 
		ImmutableList.of("2014","2015","2016","2017","201712","2018","2019").forEach(nd ->{
			for(int i=0;i<5;i++){ 
				int ym = i;
				a.add(CompletableFuture.runAsync(() -> {
					 
					HttpClient clientCode = getClient(); 
					String imgUrl = "http://192.168.0.20:8082/cf_fpb/fupin?iw-apikey=123&iw-cmd=pinkunhuxinxiliebiao&ND="+nd+"&SZXIAN=150402000000&YM="+ym;
					HttpGet siginPostCode = new HttpGet(imgUrl); 
					siginPostCode.setHeader("User-Agent",FPBSend.agent); 
					HttpResponse HtmlRespCode;
					try {
						HtmlRespCode = clientCode.execute(siginPostCode);
						System.out.println(imgUrl+"返回结果为："+EntityUtils.toString(HtmlRespCode.getEntity(), "UTF-8")); 
					} catch (IOException e){ 
						e.printStackTrace();
					}    
					
				}));
			}
		}); 
		CompletableFuture.allOf(a.toArray(new CompletableFuture[a.size()])).get();
	}
	
	
	public HttpClient getClient(){ 
		return  HttpClients.createDefault();
	}
	 
}
